<template>
  <div class="page-container">
    <div v-show="!authShow">
    <!--工具栏-->
    <div class="toolbar" style="float:left;padding-top:10px;padding-left:15px;">
      <el-form :inline="true" :model="filters" :size="size" ref="filters">

        <el-form-item prop="code">
          <el-input v-model="filters.t1" placeholder="用户姓名"></el-input>
        </el-form-item>
          <el-form-item prop="code">
          <el-input v-model="filters.code" placeholder="工号"></el-input>
        </el-form-item>
        <el-form-item prop="code">
          <el-input v-model="filters.id" placeholder="用户账号"></el-input>
        </el-form-item>
          <el-form-item prop="code">
          <el-input v-model="filters.t2" placeholder="手机号"></el-input>
        </el-form-item>
        
        <el-row>
         <el-form-item prop="shopid">
          <el-select v-model="filters.status1"  placeholder="状态" style="width:215px">
            <el-option label="停用" value="1"></el-option>
            <el-option label="启用" value="2"></el-option>
            <el-option label="已注销" value="3"></el-option>
          </el-select>
        </el-form-item>
        
         <el-form-item prop="post">
          <el-select v-model="filters.post"  placeholder="岗位" style="width:215px">
            <el-option label="经理" value="1"></el-option>
            <el-option label="运营" value="2"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop="business">
          <el-select v-model="filters.business"  placeholder="所属供应商" style="width:215px">
            <el-option label="供应商1" value="1"></el-option>
            <el-option label="供应商2" value="2"></el-option>
            <el-option label="供应商3" value="3"></el-option>
          </el-select>
        </el-form-item>
        </el-row>


      
        <el-row>
          <!-- <el-form-item>
            <kt-button
              icon="fa fa-search"
              :label="$t('action.search')"
              type="primary"
              @click="findPage(null)"
            />
          </el-form-item> -->
          <el-form-item>
            <kt-button
              icon="fa fa-plus"
              :label="$t('action.add')"
              type="primary"
              @click="handleAdd"
            />
          </el-form-item>
          <!-- <el-form-item>
            <kt-button icon="fa fa-refresh" :label="$t('action.reset')" type="primary" @click="resetForm('filters')"/>
          </el-form-item> -->
          <el-form-item>
            <kt-button label="批量停用" type="primary" @click="operationReminder('filters')"/>
          </el-form-item>
          <el-form-item>
            <kt-button label="批量添加" type="primary" @click="operationReminder('filters')"/>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <!-- <el-form :inline="true" :size="size">
        <el-form-item>
          <el-button-group>
            <el-tooltip content="刷新" placement="top">
              <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
            </el-tooltip>
            <el-tooltip content="列显示" placement="top">
              <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
            </el-tooltip>
            <el-tooltip content="导出" placement="top">
              <el-button icon="fa fa-file-excel-o" @click="downloadExcel"></el-button>
            </el-tooltip>
          </el-button-group>
        </el-form-item>
      </el-form> -->
      <!--表格显示列界面-->
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>
    <!--表格内容栏-->
    <cy-table
      :height="350"
      :data="pageResult"
      :columns="filterColumns"
      :customLabel='"功能权限"'
      :showCustomOperation="true"
      :showDeleteOperation="false"
      @handleCustom="cancelClick"
      @findPage="findPage"
      @selectionChange="selectionChange"
      @handleDelete="handleDelete"
      @handleEdit="handleEdit"
      ref="CyTable"
    ></cy-table>
    <!--新增编辑界面-->
    <el-dialog
      :title="operation?'新增':'编辑'"
      width="50%"
      :visible.sync="editDialogVisible"
      :close-on-click-modal="false"
    >
      <el-form
        :model="dataForm"
        label-width="120px"
        :rules="dataFormRules"
        ref="dataForm"
        :size="size"
      >
        <el-form-item label="id" prop="id" v-if="false">
          <el-input v-model="dataForm.id" :disabled="true" auto-complete="off"></el-input>
        </el-form-item>

       <el-form-item label="用户账号" class="styleReplace0"  prop="serveno">
          <el-input v-model="dataForm.t1" auto-complete="off" :disabled="false"  ></el-input>
        </el-form-item>
        <el-form-item label="姓名" class="styleReplace1"  prop="serveno">
          <el-input v-model="dataForm.t2" auto-complete="off" :disabled="false"  ></el-input>
        </el-form-item>
        <el-form-item label="手机号" class="styleReplace2"  prop="serveno">
          <el-input v-model="dataForm.t3" auto-complete="off" :disabled="false"  ></el-input>
        </el-form-item>
        <el-form-item prop="business" label="所属供应商">
          <el-select v-model="dataForm.t4"  placeholder="所属供应商" style="width:215px">
            <el-option label="供应商1" value="1"></el-option>
            <el-option label="供应商2" value="2"></el-option>
            <el-option label="供应商3" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="business" label="性别">
          <el-select v-model="dataForm.t5"  placeholder="性别" style="width:215px">
            <el-option label="男" value="1"></el-option>
            <el-option label="女" value="2"></el-option>
            <el-option label="保密" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="生日" class="styleReplace1"  prop="serven1">
          <el-date-picker
            v-model="dataForm.t6"
            align="right"
            type="date"
            placeholder="选择日期"
            :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="头像" prop="dpic">
          <el-upload
            v-model="dataForm.t7"
            class="avatar-uploader"
            :action="imgUrl"
            :show-file-list="false"
            :on-success="handleAvatarSuccess">
            <img v-if="dataForm.dpic" :src="dataForm.dpic" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon"></i>
          </el-upload>
        </el-form-item>

        
      </el-form>

      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button :size="size" @click.native="editDialogVisible = false">{{$t('action.cancel')}}</el-button>
        <el-button
          :size="size"
          type="primary"
          @click.native="submitForm"
          :loading="editLoading"
        >{{$t('action.submit')}}
        </el-button>
      </div>
    </el-dialog>
  </div>

    <div v-show="authShow">
      <authProviderAccountManage @cancelClick="cancelClick"></authProviderAccountManage>
    </div>
  </div>
</template>

<script>
  import CyTable from "@/views/Core/CyTable";
  import KtButton from "@/views/Core/KtButton";
  import {format} from "@/utils/datetime";
  import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";
  import { quillEditor } from 'vue-quill-editor'
  import 'quill/dist/quill.core.css'
  import 'quill/dist/quill.snow.css'
  import 'quill/dist/quill.bubble.css'
  import authProviderAccountManage from "@/views/Pages/UserCenter/authProviderAccountManage";


  export default {
    components: {
      CyTable,
      KtButton,
      TableColumnFilterDialog,
      quillEditor,
      authProviderAccountManage
    },
    data() {
      return {
        operation: false, // true:新增, false:编辑
        authShow:false,
        imgUrl:this.utils.imgUploadUrl,
        pickerOptions: {
          disabledDate(time) {
            return time.getTime() > Date.now();
          },
          shortcuts: [{
            text: '今天',
            onClick(picker) {
              picker.$emit('pick', new Date());
            }
          }]
          },
          value2:"",
        size: "small",
        filters: {
          id:"",
          t1:"",
          t2:"",
          code:"",
          name:"",
          status:"",
          res:{
            "total": 1,
            "code": "0000",
            "rows": [{
              "account": "210008",
              "name": "京东",
              "type": "第三方电商",
              "model":"BBC",
              "position": "开启",
              "jobNumber": "开启",
              "status": "开启"
            }]
          }
        },
        columns: [
          {prop: "account", label: "用户账号", minWidth: 100},
          {prop: "name", label: "姓名", minWidth: 120},
          {prop: "type", label: "所属供应商", minWidth: 120},
          {prop: "model", label: "手机号", minWidth: 120},
          {prop: "position", label: "岗位", minWidth: 120},
          {prop: "jobNumber", label: "工号", minWidth: 120},
          {prop: "status", label: "状态", minWidth: 120}
        ],
        filterColumns: [],
        pageRequest: {pageNum: 1, pageSize: 10},
        pageResult: {},

        operation: false, // true:新增, false:编辑
        editDialogVisible: false, // 新增编辑界面是否显示
        editLoading: false,
        dataFormRules: {
          replyContent: [{required: true, message: "回复内容", trigger: "blur"}]
        },
        // 新增编辑界面数据
        dataForm: {
          id: "",
          t1: "",
          t2: "",
          t3: "",
          t4: "",
          t5: "",
          t6: "",
          t7: "",
          t8: "",
          dpic:""
        },
        shopList: [],
        statusList: [],
        checked: []
      };
    },
    methods: {
      cancelClick(){
        this.authShow  = !this.authShow;
      },
      //功能权限
      // handleAuth: function (data) {
      //   this.cancelClick();
      //   console.log("1------------------------")
      //   console.log(data)
      //   console.log("2------------------------")
      // },
      handleAvatarSuccess(res, file) {
        // this.imageUrl = URL.createObjectURL(file.raw);
        console.log(res);
        // debugger;
        this.dataForm.dpic = res.data.imgUrl;
      },
      // 获取分页数据
      findPage: function (data) {
        this.$refs.CyTable.findPageStaticState(this.filters);
      },
      // 显示新增界面
      handleAdd: function () {
        this.editDialogVisible = true;
        this.operation = true;
        this.resetForm("dataForm");
      },
      // 显示编辑界面
      handleEdit: function (params) {
        this.editDialogVisible = true;
        this.operation = false;
        this.$nextTick(function () {
          console.log("1--------------------");
          console.log(params.row);
          console.log("2--------------------");

          this.dataForm = Object.assign({}, params.row);
        });
      },
      //选择框
      selectionChange: function (params) {
        this.checked = params.selections
      },
      // 批量删除
      handleDelete: function (data) {
        if (data != null && data.params != null && data.params.length > 0) {
          let ids = data.params.map(item => item.id).toString();

          var params = {};
          params.t = "changeProduct";
          params.ids = ids;
          var this_ = this;
          this.utils.request.deleteUserInfo(params, function (res) {
            if (res.code == "0000") {
              this_.$message({message: "操作成功", type: "success"});
              this_.findPage(null);
            } else {
              this_.$message({message: "操作失败, " + res.msg, type: "error"});
            }
          });
        }
      },
      // 编辑
      submitForm: function () {
        this.$refs.dataForm.validate(valid => {
          if (valid) {
            this.$confirm("确认提交吗？", "提示", {}).then(() => {
              let params = Object.assign({}, this.dataForm);
              params.t = "changeProduct";
              var this_ = this;
              this.utils.request.editInfo(params, function (res) {
                if (res.code == "0000") {
                  this_.$message({message: "操作成功", type: "success"});

                  this_.$refs["dataForm"].resetFields();

                  this_.editDialogVisible = false;

                  this_.findPage(null);
                } else {
                  this_.$message({
                    message: "操作失败, " + res.msg,
                    type: "error"
                  });
                }
              });
            });
          }
        });
      },

      // 时间格式化
      dateFormat: function (row, column, cellValue, index) {
        return format(row[column.property]);
      },

      resetForm(formName) {
        if (this.$refs[formName] != undefined) {
          this.$refs[formName].resetFields();
          this.filters.start_time = "";
          this.filters.end_time = "";
          this.findPage(null);
        }
      },

      
      operationReminder(formName) {
          this.$message({message: "操作成功", type: "success"});
      },

      // 处理表格列过滤显示
      displayFilterColumnsDialog: function () {
        this.$refs.tableColumnFilterDialog.setDialogVisible(true);
      },
      // 处理表格列过滤显示
      handleFilterColumns: function (data) {
        this.filterColumns = data.filterColumns;
        this.$refs.tableColumnFilterDialog.setDialogVisible(false);
      },
      // 处理表格列过滤显示
      initColumns: function () {
        let temp = [];

        $.each(this.columns, function (key, val) {
          temp.push(val);
        });
        this.filterColumns = temp;
      },
      //列表下载
      downloadExcel() {
        this.$confirm("确定下载列表文件?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        })
          .then(() => {
            let filename = "换货管理下载";
            this.$refs.CyTable.exportData(
              this.filters,
              this.filterColumns,
              filename
            );
          })
          .catch(() => {
          });
      }
    },
    mounted() {
      this.initColumns()
    }
  };
</script>

<style scoped>
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
